sherlock and the valid string hackerrank solution